package com.glodon.paas.document.web.resource.internal;

import static org.apache.http.params.HttpConnectionParams.*;

import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpParams;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

@Ignore
public class StoreResourceIT {

    @Test
    @Ignore
    public void upload() throws Exception {
        Resource resource = new FileSystemResource("/Volumes/tmp/mou.md");
        long length = resource.getFile().length();
        HttpClient client = new DefaultHttpClient();
        HttpParams params = client.getParams();
        setSoTimeout(params, 3000);
        setConnectionTimeout(params, 3000);
        HttpPost post = new HttpPost("http://172.16.107.244:8080/document/api/internal/store/c@c.com/bbb/aaa.md");
        post.addHeader(HttpHeaders.CONTENT_TYPE, "application/octet-stream");
        post.setEntity(new InputStreamEntity(resource.getInputStream(), length));
        HttpResponse resp = client.execute(post);
        System.out.println(resp);
    }

    @Test
    // @Ignore
    public void delete() throws Exception {
        HttpDelete del = new HttpDelete("http://172.16.107.244:8080/document/api/internal/store/c@c.com/bbb/aaa.md");
        HttpClient client = new DefaultHttpClient();
        HttpParams params = client.getParams();
        setSoTimeout(params, 3000);
        setConnectionTimeout(params, 3000);
        HttpResponse resp = client.execute(del);
        System.out.println(resp);
    }
}
